package com.honeyms.project.blog.blognotice.controller;

import java.util.List;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.honeyms.framework.aspectj.lang.annotation.Log;
import com.honeyms.framework.aspectj.lang.enums.BusinessType;
import com.honeyms.project.blog.blognotice.domain.BlogNotice;
import com.honeyms.project.blog.blognotice.service.IBlogNoticeService;
import com.honeyms.framework.web.controller.BaseController;
import com.honeyms.framework.web.domain.AjaxResult;
import com.honeyms.common.utils.poi.ExcelUtil;
import com.honeyms.framework.web.page.TableDataInfo;

/**
 * 博客通知Controller
 * 
 * @author honeyms
 * @date 2020-11-06
 */
@Controller
@RequestMapping("/blog/blognotice")
public class BlogNoticeController extends BaseController
{
    private String prefix = "blog/blognotice";

    @Autowired
    private IBlogNoticeService blogNoticeService;

    @RequiresPermissions("blog:blognotice:view")
    @GetMapping()
    public String blognotice()
    {
        return prefix + "/blognotice";
    }

    /**
     * 查询博客通知列表
     */
    @RequiresPermissions("blog:blognotice:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(BlogNotice blogNotice)
    {
        startPage();
        List<BlogNotice> list = blogNoticeService.selectBlogNoticeList(blogNotice);
        return getDataTable(list);
    }

    /**
     * 导出博客通知列表
     */
    @RequiresPermissions("blog:blognotice:export")
    @Log(title = "博客通知", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(BlogNotice blogNotice)
    {
        List<BlogNotice> list = blogNoticeService.selectBlogNoticeList(blogNotice);
        ExcelUtil<BlogNotice> util = new ExcelUtil<BlogNotice>(BlogNotice.class);
        return util.exportExcel(list, "blognotice");
    }

    /**
     * 新增博客通知
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存博客通知
     */
    @RequiresPermissions("blog:blognotice:add")
    @Log(title = "博客通知", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(BlogNotice blogNotice)
    {
    	blogNotice.setCreateId(getUserId());
        return toAjax(blogNoticeService.insertBlogNotice(blogNotice));
    }

    /**
     * 修改博客通知
     */
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") Long id, ModelMap mmap)
    {
        BlogNotice blogNotice = blogNoticeService.selectBlogNoticeById(id);
        mmap.put("blogNotice", blogNotice);
        return prefix + "/edit";
    }

    /**
     * 修改保存博客通知
     */
    @RequiresPermissions("blog:blognotice:edit")
    @Log(title = "博客通知", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(BlogNotice blogNotice)
    {
        return toAjax(blogNoticeService.updateBlogNotice(blogNotice));
    }

    /**
     * 删除博客通知
     */
    @RequiresPermissions("blog:blognotice:remove")
    @Log(title = "博客通知", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(blogNoticeService.deleteBlogNoticeByIds(ids));
    }
}
